package cn.bby.query.example.controller;

import cn.bby.jtk.web.CommonResult;
import cn.bby.query.base.ann.QueryInterface;
import cn.bby.query.base.constant.QueryCondition;
import cn.bby.query.base.model.req.Filter;
import cn.bby.query.base.model.req.QueryRequest;
import cn.bby.query.base.model.req.QueryResponse;
import cn.bby.query.example.model.entity.OrderInfo;
import cn.bby.query.example.model.entity.vo.OrderInfoVO;
import cn.bby.query.example.service.OrderInfoService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * 货物信息(OrderInfo)表控制层
 *
 * @author makejava
 * @since 2025-04-12 01:58:09
 */
@RestController
@RequestMapping("OrderInfo")
public class OrderInfoController {
    /**
     * 服务对象
     */
    @Resource
    private OrderInfoService orderInfoService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @PostMapping("QueryOrderInfoList")
    @QueryInterface(name = "QueryOrderInfoList")
    public CommonResult<QueryResponse<OrderInfoVO>> describeOrderInfoList(@RequestBody QueryRequest request) {
        return CommonResult.success(this.orderInfoService.queryList(request));
    }

    /**
     * 分页查询少量
     *
     * @return 查询结果
     */
    @PostMapping("QueryOrderInfoListLite")
    @QueryInterface(name = "QueryOrderInfoListLite")
    public CommonResult<QueryResponse<OrderInfoVO>> describeOrderInfoListLite(@RequestBody QueryRequest request) {
        List<Filter> filters = request.getFilters();
        filters = filters == null ? new ArrayList<>() : new ArrayList<>(filters);
        filters.add(new Filter("order_id", QueryCondition.LESS_THEN, List.of("20000")));
        request.setFilters(filters);
        return CommonResult.success(this.orderInfoService.queryList(request));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderInfo> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.orderInfoService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param OrderInfo 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<OrderInfo> add(OrderInfo OrderInfo) {
        return ResponseEntity.ok(this.orderInfoService.insert(OrderInfo));
    }

    /**
     * 编辑数据
     *
     * @param OrderInfo 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<OrderInfo> edit(OrderInfo OrderInfo) {
        return ResponseEntity.ok(this.orderInfoService.update(OrderInfo));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.orderInfoService.deleteById(id));
    }

}

